package com.avengers.modules.spider.whois.querier;

import com.avengers.modules.spider.whois.bean.WhoisInfo;

import java.util.ArrayList;

/**
 * @author yu.wang
 * @since 2019/1/2 上午11:52
 * <p>
 * Domain Name: ABC.COM
 * Registry Domain ID: 893646_DOMAIN_COM-VRSN
 * Registrar WHOIS Server: whois.corporatedomains.com
 * Registrar URL: http://www.cscglobal.com/global/web/csc/digital-brand-services.html
 * Updated Date: 2018-08-08T23:38:25Z
 * Creation Date: 1996-05-22T04:00:00Z
 * Registry Expiry Date: 2019-05-23T04:00:00Z
 * Registrar: CSC Corporate Domains, Inc.
 * Registrar IANA ID: 299
 * Registrar Abuse Contact Email: domainabuse@cscglobal.com
 * Registrar Abuse Contact Phone: 8887802723
 * Domain Status: clientTransferProhibited https://icann.org/epp#clientTransferProhibited
 * Domain Status: serverDeleteProhibited https://icann.org/epp#serverDeleteProhibited
 * Domain Status: serverTransferProhibited https://icann.org/epp#serverTransferProhibited
 * Domain Status: serverUpdateProhibited https://icann.org/epp#serverUpdateProhibited
 * Name Server: ORNS01.DIG.COM
 * Name Server: ORNS02.DIG.COM
 * Name Server: SENS01.DIG.COM
 * Name Server: SENS02.DIG.COM
 * DNSSEC: unsigned
 **/
class ComNet implements WhoisAnalysis {
    public static final ComNet ANALYSIS = new ComNet();

    private ComNet() {
    }

    @Override
    public String server() {
        return "whois.verisign-grs.com";
    }

    @Override
    public String notFoundRemark() {
        return "No match for";
    }

    @Override
    public String unRegisteredOnLineRemark() {
        return null;
    }

    @Override
    public void transferLine(WhoisInfo info, String line) {
        if (line.contains("Registry Domain ID:")) {
            info.setRegistryDomainId(line.replace("Registry Domain ID:", "").trim());
        } else if (line.contains("Registrar WHOIS Server:")) {
            info.setRegistrarWhoisServer(line.replace("Registrar WHOIS Server:", "").trim());
        } else if (line.contains("Registrar URL:")) {
            info.setRegistrarUrl(line.replace("Registrar URL:", "").trim());
        } else if (line.contains("Updated Date:")) {
            info.setUpdateDate(line.replace("Updated Date:", "").trim());
        } else if (line.contains("Creation Date:")) {
            info.setCreateDate(line.replace("Creation Date:", "").trim());
        } else if (line.contains("Registry Expiry Date:") || line.contains("Registrar Registration Expiration Date:")) {
            info.setExpiryDate(line.replace("Registry Expiry Date:", "").replace("Registrar Registration Expiration Date:", "").trim());
        } else if (line.contains("Registrar:")) {
            info.setRegistrar(line.replace("Registrar:", "").trim());
        } else if (line.contains("Registrar IANA ID:")) {
            info.setRegistrarId(line.replace("Registrar IANA ID:", "").trim());
        } else if (line.contains("Registrar Abuse Contact Email:")) {
            info.setContactEmail(line.replace("Registrar Abuse Contact Email:", "").trim());
        } else if (line.contains("Registrar Abuse Contact Phone:")) {
            info.setContactPhone(line.replace("Registrar Abuse Contact Phone:", "").trim());
        } else if (line.contains("Domain Status:")) {
            if (null == info.getStatusList()) {
                info.setStatusList(new ArrayList<>());
            }
            int endIndex = line.indexOf("http");
            info.getStatusList().add(line.substring(0, endIndex).replace("Domain Status:", "").trim());
        } else if (line.contains("Name Server:")) {
            if (null == info.getNameServerList()) {
                info.setNameServerList(new ArrayList<>());
            }
            info.getNameServerList().add(line.replace("Name Server: ", "").trim());
        } else if (line.contains("DNSSEC:")) {
            info.setDnsSec(line.replace("DNSSEC:", "").trim());
        }
    }
}
